package edu.hebeu.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import edu.hebeu.entity.Employee;
import edu.hebeu.entity.Employee2;
import edu.hebeu.entity.Leave;
import edu.hebeu.mapper.EmployeeMapper;
import edu.hebeu.mapper.LeaveMapper;
import edu.hebeu.service.EmployeeService;
import edu.hebeu.service.LeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LeaveServiceImpl extends ServiceImpl<LeaveMapper, Leave>  implements LeaveService {
    @Autowired
private  LeaveMapper leaveMapper;
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public Page<Leave> selectPag(Integer pageNo) {
        Page<Leave> page = new Page<>(pageNo, 3, "id");
        page.setAsc(false);
        EntityWrapper<Leave> wrapper = new EntityWrapper<>();
        List<Leave> list = baseMapper.selectPage(page, wrapper);
        for (Leave leave : list) {
            setObject(leave);
           /* Integer employeeNumber = leave.getEmployeeNumber();
            Employee employee = employeeMapper.selectByNumber(employeeNumber);
            leave.setEmployee(employee);*/
        }
        page.setRecords(list);
        return page;
    }

    private void setObject(Leave leave) {
        Integer employeeNumber = leave.getEmployeeNumber();
        Employee employee = employeeMapper.selectByNumber(employeeNumber);
        leave.setEmployee(employee);
    }
    
}
